﻿using Abp.Application.Services;
using Abp.Domain.Repositories;
using Abp.Web.Models;
using Batman.RefiningPharmacist.Domains;
using Batman.RefiningPharmacist.Services.Inputs;
using System.Collections.Generic;

namespace Batman.RefiningPharmacist.Services
{
    public class CompositeManager : ApplicationService
    {
        public IRepository<Composite> Repository { get; set; }

        /// <summary>
        /// 新建合成物数据接口
        /// </summary>
        /// <param name="model"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public AjaxResponse<Composite> Create(CreateCompositeInput model, string userId)
        {
            var entity = ObjectMapper.Map<Composite>(model);
            entity.InitOnCreate(userId);
            entity.CompositeItems.ForEach(t => t.InitOnCreate(userId));

            var newComposite = Repository.Insert(entity);

            return new AjaxResponse<Composite>(newComposite);
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="ids"></param> 
        public void Destroy(List<int> ids)
        {
            ids.ForEach(t => Repository.Update(t, s => s.IsDeleted = true));
        }
    }
}
